// 全局混入mixin

export default {
  data () {
    return {
      mix: '混入数据'
    }
  },
  directives: {
    move: {
      bind () {
        console.log('bind')
      },
      update (el, binding) {
        console.log('update')
        console.log(el.innerHTML)
        console.log('当前值：' + binding.value)
        console.log('旧值：' + binding.oldValue)
      },
      componentUpdated (el, binding) {
        // 对比nextTick
        console.log('componentUpdated')
        console.log(el.innerHTML)
      },
      inserted: function (el, binding) {
        console.log('inserted')
        console.log(binding.value)
        var _d = binding.modifiers.left ? '-' : ''
        var startX = 0
        var _x = 0
        el.addEventListener(
          'touchstart',
          function (e) {
            _x = startX = e.touches[0].pageX
          },
          false
        )
        el.addEventListener(
          'touchmove',
          function (e) {
            _x = e.touches[0].pageX
          },
          false
        )
        el.addEventListener(
          'touchend',
          function () {
            if (startX >= _x) {
              if (binding.modifiers.left) {
                el.style.transform = 'translateX(' + _d + binding.value + 'px)'
              } else {
                el.style.transform = 'translateX(0)'
              }
            } else {
              if (binding.modifiers.left) {
                el.style.transform = 'translateX(0px)'
              } else {
                el.style.transform = 'translateX(' + _d + binding.value + 'px)'
              }
            }
          },
          false
        )
      }
    }
  }
}
